package jnpf.onlinedev.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.base.UserInfo;
import jnpf.base.model.VisualDevJsonModel;
import jnpf.base.model.VisualWebTypeEnum;
import jnpf.base.service.DbLinkService;
import jnpf.base.util.VisualUtils;
import jnpf.database.model.dto.PrepareSqlDTO;
import jnpf.database.model.entity.DbLinkEntity;
import jnpf.database.model.page.JdbcPageMod;
import jnpf.database.util.JdbcUtil;
import jnpf.engine.entity.FlowTaskEntity;
import jnpf.engine.service.FlowTaskService;
import jnpf.engine.util.FlowDataUtil;
import jnpf.model.visiual.*;
import jnpf.model.visiual.fields.FieLdsModel;
import jnpf.model.visiual.superQuery.ConditionJsonModel;
import jnpf.model.visiual.superQuery.SuperQueryJsonModel;
import jnpf.onlinedev.entity.VisualdevModelDataEntity;
import jnpf.onlinedev.mapper.VisualdevModelDataMapper;
import jnpf.onlinedev.model.OnlineDevListModel.OnlineColumnFieldModel;
import jnpf.onlinedev.model.OnlineDevListModel.OnlineFieldsModel;
import jnpf.onlinedev.model.OnlineDevListModel.VisualColumnSearchVO;
import jnpf.onlinedev.model.PaginationModel;
import jnpf.onlinedev.service.VisualDevListService;
import jnpf.onlinedev.util.AutoFeildsUtil;
import jnpf.onlinedev.util.onlineDevUtil.*;
import jnpf.permission.service.AuthorizeService;
import jnpf.util.JsonUtil;
import jnpf.util.PageUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import lombok.Cleanup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.util.*;
import java.util.stream.Collectors;

/**
 *
 * 在线开发列表
 * @author JNPF开发平台组
 * @version V3.2.0
 * @copyright 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * @date  2021/7/28
 */
@Service
public class VisualDevListServiceImpl extends ServiceImpl<VisualdevModelDataMapper, VisualdevModelDataEntity> implements VisualDevListService {
	@Autowired
	private DbLinkService dblinkService;
	@Autowired
	private FlowTaskService flowTaskService;
	@Autowired
	private UserProvider userProvider;
	@Autowired
	private OnlineSwapDataUtils onlineSwapDataUtils;
	@Autowired
	private FlowDataUtil flowDataUtil;
	@Autowired
	private AuthorizeService authorizeService;

	@Override
	public List<Map<String, Object>> getDataList(VisualDevJsonModel visualDevJsonModel, PaginationModel paginationModel) {

		List<Map<String, Object>> realList;
		ColumnDataModel columnDataModel = visualDevJsonModel.getColumnData();
		FormDataModel formDataModel = visualDevJsonModel.getFormData();
		List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
		List<TableModel> visualTables = visualDevJsonModel.getVisualTables();
		TableModel mainTable = visualTables.stream().filter(vi -> vi.getTypeId().equals("1")).findFirst().orElse(null);
		List<VisualColumnSearchVO> searchVOList = new ArrayList<>();
		List<VisualColumnSearchVO> searchVOS = new ArrayList<>();
		//封装查询条件
		if (StringUtil.isNotEmpty(paginationModel.getQueryJson())){
			Map<String, Object> keyJsonMap = JsonUtil.stringToMap(paginationModel.getQueryJson());
			searchVOList= JsonUtil.getJsonToList(columnDataModel.getSearchList(),VisualColumnSearchVO.class);
			searchVOList =	searchVOList.stream().map(searchVO->{
				searchVO.setValue(keyJsonMap.get(searchVO.getVModel()));
				return searchVO;
			}).filter(vo->vo.getValue()!=null).collect(Collectors.toList());
			//左侧树查询
			boolean b =false;
			if (columnDataModel.getTreeRelation()!=null){
				b = keyJsonMap.keySet().stream().anyMatch(t -> t.equalsIgnoreCase(String.valueOf(columnDataModel.getTreeRelation())));
			}
			if (b && keyJsonMap.size()>searchVOList.size()){
				String relation =String.valueOf(columnDataModel.getTreeRelation());
				String treeDataSource = columnDataModel.getTreeDataSource();
				VisualColumnSearchVO vo =new VisualColumnSearchVO();
				//从列表控件中 赋予左侧树查询条件属性
				FieLdsModel fieLdsModel = AutoFeildsUtil.getTreeRelationSearch(fieLdsModels,relation);
				vo.setConfig(Objects.nonNull(fieLdsModel) ? fieLdsModel.getConfig() : null);
				Boolean multiple = fieLdsModel.getMultiple();
				if (treeDataSource.equals("organize")){
					vo.setSearchType("1");
				}else {
					vo.setSearchType(multiple ? "2" :"1");
				}
				vo.setVModel(relation);
				vo.setValue(keyJsonMap.get(relation));
				searchVOList.add(vo);
			}
		}
		//递归处理控件
		List<FieLdsModel> fields = OnlinePublicUtils.recursionFields(visualTables, fieLdsModels);
		visualDevJsonModel.setFormListModels(fields);
		//判断有无表
		if (visualTables.size()>0){
			//当前用户信息
			UserInfo userInfo = userProvider.get();
			//菜单id
			String moduleId = paginationModel.getMenuId();
			for (VisualColumnSearchVO vo : searchVOList){
				String vModel = vo.getVModel();
				if (vModel.startsWith("tableField")){
					vo.setField(vModel.substring(vModel.lastIndexOf("-")+1));
					vo.setTable(vo.getConfig().getRelationTable());
				} else if (vModel.contains("jnpf_")){
					String fieldName = vModel.substring(vModel.lastIndexOf("jnpf_" )).replace("jnpf_", "" );
					String tableName = vModel.substring(vModel.indexOf("_" ) + 1, vModel.lastIndexOf("_jnpf" ));
					vo.setTable(tableName);
					vo.setField(fieldName);
				} else {
					vo.setField(vModel);
					vo.setTable(mainTable.getTable());
				}
				searchVOS.add(vo);
			}
			realList = this.getListWithTable(visualDevJsonModel,paginationModel,userInfo,moduleId,searchVOS,null);
		}else{
			realList =this.getWithoutTableData(visualDevJsonModel.getId());
			realList = this.getList(realList, searchVOS, paginationModel);
		}

		if (realList.size()<1){
			return realList;
		}
		//编辑表格(行内编辑)
		boolean inlineEdit = columnDataModel.getType()!=null && columnDataModel.getType() == 4;

		//数据转换
		realList = onlineSwapDataUtils.getSwapList(realList, fields,visualDevJsonModel.getId(),inlineEdit, new ArrayList<>());

			//添加流程状态
			if(visualDevJsonModel.getWebType()!=null){
				if (visualDevJsonModel.getWebType().equals(VisualWebTypeEnum.FLOW_FROM.getType())){
					List<String> ids = realList.stream().map(i->i.get("id").toString()).collect(Collectors.toList());
					List<FlowTaskEntity> tasks = flowTaskService.getInfosSubmit(ids.toArray(new String[]{}), FlowTaskEntity::getStatus, FlowTaskEntity::getId, FlowTaskEntity::getProcessId);
					realList.stream().forEach(m->{
						String id = m.get("id").toString();
						m.put("flowState","");
						tasks.forEach(i->{
							if(i.getId().equals(id) || i.getProcessId().equals(id)){
								m.put("flowState", i.getStatus());
							}
						});
					});
				}
			}
		return realList;
	}

	@Override
	public List<Map<String, Object>> getList(List<Map<String, Object>> noSwapDataList, List<VisualColumnSearchVO> searchVOList, PaginationModel paginationModel) {
		if (searchVOList.size() > 0) {
			//条件查询
			noSwapDataList = OnlineDevListUtils.getNoSwapList(noSwapDataList, searchVOList);
		}
		//排序
		if (noSwapDataList.size() > 0) {
			if (StringUtil.isNotEmpty(paginationModel.getSidx())) {
				//排序处理
				noSwapDataList.sort((o1, o2) -> {
					Map<String, Object> i1 = o1;
					Map<String, Object> i2 = o2;
					String s1 = String.valueOf(i1.get(paginationModel.getSidx()));
					String s2 = String.valueOf(i2.get(paginationModel.getSidx()));
					if ("desc".equalsIgnoreCase(paginationModel.getSort())) {
						return s2.compareTo(s1);
					} else {
						return s1.compareTo(s2);
					}
				});
			}

			long total = noSwapDataList.size();

			//数据分页
			noSwapDataList = PageUtil.getListPage((int) paginationModel.getCurrentPage(), (int) paginationModel.getPageSize(), noSwapDataList);
			noSwapDataList = paginationModel.setData(noSwapDataList, total);
		}
		return noSwapDataList;
	}

	@Override
	public List<Map<String,Object>> getWithoutTableData(String modelId) {
		QueryWrapper<VisualdevModelDataEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.lambda().eq(VisualdevModelDataEntity::getVisualDevId, modelId);
		List<VisualdevModelDataEntity> list = this.list(queryWrapper);
		List<Map<String,Object>> dataVoList = list.parallelStream().map(t -> {
			Map<String,Object> dataMap= JsonUtil.stringToMap(t.getData());
			dataMap.put("id",t.getId());
			return dataMap;
		}).collect(Collectors.toList());
		return dataVoList;
	}

	@Override
	public List<Map<String, Object>> getListWithTable(VisualDevJsonModel visualDevJsonModel, PaginationModel paginationModel,
																										UserInfo userInfo,String moduleId,List<VisualColumnSearchVO> searchVOList,List<String> columnPropList) {

		ColumnDataModel columnDataModel = visualDevJsonModel.getColumnData();
		List<Map<String,Object>> dataList = new ArrayList<>();

		//数据源
		DbLinkEntity linkEntity = dblinkService.getInfo(visualDevJsonModel.getDbLinkId());
	try {
		@Cleanup Connection connection = VisualUtils.getDataConn(linkEntity);
		String databaseProductName = connection.getMetaData().getDatabaseProductName().trim();
		List<TableModel> tableModelList = visualDevJsonModel.getVisualTables();
		//主表
		TableModel mainTable = tableModelList.stream().filter(t -> t.getTypeId().equals("1")).findFirst().orElse(null);

		List<ColumnListField> modelList = JsonUtil.getJsonToList(columnDataModel.getColumnList(), ColumnListField.class);

		StringBuilder mainSql = new StringBuilder();

		//列表中区别子表正则
		String reg = "^[jnpf_]\\S*_jnpf\\S*";

		//所有字段
		List<String> collect = columnPropList!=null ? columnPropList : modelList.stream().map(mode -> mode.getProp()).collect(Collectors.toList());
		FormDataModel formData = visualDevJsonModel.getFormData();
		List<FieLdsModel> jsonToList = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);

		Map<String,String> tableFieldAndTableName = new HashMap<>(8);
		Map<String,String> tableNameAndTableField = new HashMap<>(8);
		jsonToList.stream().filter(f->f.getConfig().getJnpfKey().equals(JnpfKeyConsts.CHILD_TABLE)).forEach(f->{
			tableFieldAndTableName.put(f.getVModel(),f.getConfig().getTableName());
			tableNameAndTableField.put(f.getConfig().getTableName(),f.getVModel());
		});

		Integer primaryKeyPolicy = formData.getPrimaryKeyPolicy();
		String pkeyId = flowDataUtil.getKey(connection, mainTable.getTable(),primaryKeyPolicy);
		if ("Oracle".equals(databaseProductName)){
			pkeyId = pkeyId.toUpperCase();
		}
		String sort;
		if (StringUtil.isNotEmpty(paginationModel.getSort())){
			sort = paginationModel.getSort();
		}else {
			sort = "ASC";
		}
		String sidx=pkeyId;
		if (StringUtil.isNotEmpty(paginationModel.getSidx())){
			sidx = paginationModel.getSidx();
			if (sidx.matches(reg)){
				String s1 = sidx.substring(sidx.lastIndexOf("jnpf_" )).replace("jnpf_", "" );
				String s2 = sidx.substring(sidx.indexOf("_" ) + 1, sidx.lastIndexOf("_jnpf" ));
				sidx = s2 + "." + s1;
			}
		}
		String sortType = sidx + "," + sort;

		OnlineFieldsModel columnListSql = OnlineProductSqlUtils.getColumnListSql(mainSql, visualDevJsonModel, collect, linkEntity);
		mainSql =columnListSql.getSql();
		List<OnlineColumnFieldModel> childValue = columnListSql.getMastTableList();
		mainSql.append(OnlineProductSqlUtils.getJoinTableSql(tableModelList,pkeyId));
		mainSql.append(" where (1=1)");
		List<Object> objectList = new ArrayList<>();
		if (searchVOList.size()>0){
			//查询条件sql
			mainSql= OnlineProductSqlUtils.getConditionSql(mainSql, linkEntity, searchVOList,objectList);
		}

		//数据权限
		if (columnDataModel.getUseDataPermission()!=null && columnDataModel.getUseDataPermission()){
			//数据权限
			if (!userInfo.getIsAdministrator()) {
				String conditionSql = authorizeService.getConditionSql(userInfo, moduleId, null,objectList);
				if (conditionSql.length()>0){
					if (!conditionSql.equals("alldata")){
						mainSql.append(conditionSql);
					}
				}
				//未分配方案不显示数据
				else {
					return new ArrayList<>();
				}
			}
		}

		//递归处理控件
		visualDevJsonModel.setFormListModels(OnlinePublicUtils.recursionFields(tableModelList, jsonToList));

		//高级查询
		String matchLogic = "";
		List<ConditionJsonModel> superQueryList = new ArrayList<>();
		if (StringUtil.isNotEmpty(paginationModel.getSuperQueryJson())){
			SuperQueryJsonModel superQueryJsonModel = JsonUtil.getJsonToBean(paginationModel.getSuperQueryJson(),SuperQueryJsonModel.class);
			matchLogic = superQueryJsonModel.getMatchLogic();
			superQueryList = JsonUtil.getJsonToList(superQueryJsonModel.getConditionJson(), ConditionJsonModel.class);
			superQueryList.stream().forEach(sup->{
				FieLdsModel fieLdsModel = JsonUtil.getJsonToBean(sup.getAttr(), FieLdsModel.class);
				sup.setTableName(fieLdsModel.getConfig().getRelationTable());
				String field = sup.getField();
				String mastKey = fieLdsModel.getConfig().getJnpfKey();
				sup.setDefaultValue(String.valueOf(fieLdsModel.getConfig().getDefaultValue()));
				if (field.toLowerCase().contains("tablefield")){
					String substring = field.substring(field.lastIndexOf("-") + 1);
					String tableField = field.substring(0,field.indexOf("-"));
					sup.setField(substring);
					sup.setTableName(tableFieldAndTableName.get(tableField));
				} else if (StringUtil.isEmpty(sup.getTableName())){
					sup.setTableName(mainTable.getTable());
				}

				if(mastKey.equals(JnpfKeyConsts.CHECKBOX) ||  mastKey.equals(JnpfKeyConsts.ADDRESS)
						|| mastKey.equals(JnpfKeyConsts.CASCADER) || mastKey.equals(JnpfKeyConsts.COMSELECT)){
					 fieLdsModel.setMultiple(true);
				}
				if (fieLdsModel.getMultiple() && StringUtil.isEmpty(sup.getFieldValue())){
					sup.setFieldValue("[]");
				}
			});
			mainSql = OnlineProductSqlUtils.getSuperSql(mainSql,superQueryList,matchLogic,objectList);
		}

		//是否导出全部数据
		if ("1".equals(paginationModel.getDataType())){
			dataList = JdbcUtil.queryListAlias(new PrepareSqlDTO(connection,mainSql.toString()));
		}else {
			JdbcPageMod jdbcPageMod = JdbcUtil.queryPage(new PrepareSqlDTO(connection, mainSql.toString(),objectList), sortType, (int) paginationModel.getCurrentPage(), (int) paginationModel.getPageSize());
			dataList = jdbcPageMod.getDataList();
			paginationModel.setTotal(jdbcPageMod.getTotalRecord());
		}

		Map<String,String> otherNameMap = new HashMap<>();
		childValue.stream().forEach(c->otherNameMap.put(c.getOtherName(),c.getOriginallyField()));
		dataList.stream().forEach(m->{
			for (Map.Entry entry : otherNameMap.entrySet()){
				m.put(entry.getValue().toString(),m.remove(entry.getKey()));
			}
		});

		String finalPkeyId = pkeyId;
		List<String> idStringList = dataList.stream().map(m -> m.get(finalPkeyId).toString()).distinct().collect(Collectors.toList());
		String ids = idStringList.stream().map(m -> "'" + m + "'").collect(Collectors.joining(","));
		ids = StringUtil.isNotEmpty(ids) ? " in ( " + ids + ")" : "" ;
		if (ids.length()>0){
			//处理子表
			List<String> tableFields = collect.stream().filter(c -> c.toLowerCase().contains("tablefield")).collect(Collectors.toList());
			List<TableModel> childTableModels = tableModelList.stream().filter(t -> t.getTypeId().equals("0")).collect(Collectors.toList());

			Map<String, List<String>> tableMap = tableFields.stream().collect(Collectors.groupingBy(t -> t.substring(0, t.lastIndexOf("-"))));
			for (TableModel tableModel : childTableModels){
				List<Object> childTableObjs = new ArrayList<>();
				String table = tableModel.getTable();
				String tableField = tableNameAndTableField.get(table);
				String relationID = tableModel.getRelationField();
				String fogID = tableModel.getTableField();
				StringBuilder contionSql = new StringBuilder();
				List<String> childFields = tableMap.get(tableField);
			if (childFields!=null){
				String fields = childFields.stream().map(c -> {
					String childT = c.substring(0, c.lastIndexOf("-"));
					String childF = c.substring(c.lastIndexOf("-")+ 1);
					return tableFieldAndTableName.get(childT) + "." + childF;
				}).collect(Collectors.joining(","));
				fields = "select " + fogID + ", " + fields + " from " + table + " where " + table + "." + fogID;
				if (superQueryList.size()>0){
					StringBuilder superSql = OnlineProductSqlUtils.getSuperSql(superQueryList, matchLogic,table,childTableObjs);
					contionSql.append(superSql);
				}
				if (searchVOList.size()>0){
					StringBuilder conditionSql1 = OnlineProductSqlUtils.getConditionSql(table, linkEntity, searchVOList,childTableObjs);
					contionSql.append(conditionSql1);
				}
				String authorizeSql = authorizeService.getConditionSql(userInfo, moduleId, table,childTableObjs);
				fields+= ids;
				if (!authorizeSql.equals("alldata")){
					fields +=authorizeSql;
				}
				fields+= contionSql;
				PrepareSqlDTO dto = new PrepareSqlDTO(connection,fields,childTableObjs);
				List<Map<String, Object>> mapList = JdbcUtil.queryList(dto);
				Map<String, List<Map<String, Object>>> idMap = mapList.stream().collect(Collectors.groupingBy(m -> m.get(fogID).toString()));

				for (Map<String,Object> m : dataList){
					String s = m.get(pkeyId).toString();
					Map<String,Object> valueMap = new HashMap<>();
					valueMap.put(tableField,idMap.get(s));
					m.putAll(valueMap);
				}
			}
			}
		}else {
			return new ArrayList<>();
		}
			dataList.stream().forEach(data ->  {
				data.put("id",String.valueOf(data.get(finalPkeyId)));
			});

		} catch (Exception e) {
			e.printStackTrace();
		}
		return dataList;
	}

	@Override
	public List<Map<String, Object>> getRelationFormList(VisualDevJsonModel visualDevJsonModel, PaginationModel paginationModel) {
		FormDataModel formData = visualDevJsonModel.getFormData();
		List<String> collect= Arrays.asList(paginationModel.getColumnOptions().split(","));
		List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);

		List<FieLdsModel> mainFieldModelList = new ArrayList<>();


		List<Map<String, Object>> noSwapDataList = new ArrayList<>();
		List<VisualColumnSearchVO> searchVOList = new ArrayList<>();
		//查询的关键字
		String keyword = paginationModel.getKeyword();
		//判断有无表
		if (visualDevJsonModel.getVisualTables().size()>0){
			try{
				List<TableModel> tableModelList = JsonUtil.getJsonToList(visualDevJsonModel.getVisualTables(),TableModel.class);

				mainFieldModelList = OnlinePublicUtils.recursionFields(tableModelList, fieLdsModels);

				//主表
				TableModel mainTable = tableModelList.stream().filter(t -> t.getTypeId().equals("1")).findFirst().orElse(null);

				DbLinkEntity linkEntity = dblinkService.getInfo(visualDevJsonModel.getDbLinkId());

				StringBuilder sql =new StringBuilder();

				//判断是否分页
				Boolean isPage =  paginationModel.getPageSize()>500 ? false : true;
				List<OnlineColumnFieldModel> childValue = new ArrayList<>();
				OnlineFieldsModel columnListSql = OnlineProductSqlUtils.getColumnListSql(sql, visualDevJsonModel, collect, linkEntity);
				sql =columnListSql.getSql();
				childValue = columnListSql.getMastTableList();
				@Cleanup Connection connection = VisualUtils.getDataConn(linkEntity);

				//第一种 有关键字查询并且分页的查询
				if (StringUtil.isNotEmpty(keyword) && isPage) {
					//只取 单行 多行可输入的值
					for (FieLdsModel fieldsModel : mainFieldModelList){
						if (fieldsModel.getVModel()!=null){
							boolean b = collect.stream().anyMatch(c ->
									fieldsModel.getVModel().equalsIgnoreCase(c)
											&& (fieldsModel.getConfig().getJnpfKey().equals(JnpfKeyConsts.COM_INPUT)
											|| fieldsModel.getConfig().getJnpfKey().equals(JnpfKeyConsts.TEXTAREA)));
							//组装为查询条件
							if (b){
								VisualColumnSearchVO vo =new VisualColumnSearchVO();
								vo.setSearchType("2");
								vo.setVModel(fieldsModel.getVModel());
								vo.setValue(keyword);
								vo.setConfig(fieldsModel.getConfig());
								Boolean multiple = fieldsModel.getMultiple();
								vo.setMultiple(multiple);
								searchVOList.add(vo);
							}
						}
					}

					if (searchVOList.size()>0){
						sql = RelationFormUtils.getRelationListByKeywordWithSql(sql,searchVOList,mainTable.getTable());
					}
				}

				String pkeyId = flowDataUtil.getKey(connection, mainTable.getTable(),visualDevJsonModel.getFormData().getPrimaryKeyPolicy());
				String sort;
				if (StringUtil.isNotEmpty(paginationModel.getSort())){
					sort = paginationModel.getSort();
				}else {
					sort = "ASC";
				}
				String sidx=pkeyId;
				if (StringUtil.isNotEmpty(paginationModel.getSidx())){
					sidx = paginationModel.getSidx();
				}
				String sortType = sidx + "," + sort;
				JdbcPageMod jdbcPageMod = JdbcUtil.queryPage(new PrepareSqlDTO(connection, sql.toString()), sortType, (int) paginationModel.getCurrentPage(), (int) paginationModel.getPageSize());
				List<Map<String,Object>> dataList = jdbcPageMod.getDataList();

				paginationModel.setTotal(jdbcPageMod.getTotalRecord());

				noSwapDataList = dataList.stream().map(data ->  {
					data.put("id",String.valueOf(data.get(pkeyId)));
					return data;
				}).collect(Collectors.toList());

				//第二种 有关键字不分页
				if (StringUtil.isNotEmpty(keyword) && !isPage){
					for (FieLdsModel fieldsModel : mainFieldModelList){
						if (fieldsModel.getVModel()!=null){
							boolean b = collect.stream().anyMatch(c ->
									fieldsModel.getVModel().equalsIgnoreCase(c)
							);
							//组装为查询条件
							if (b){
								VisualColumnSearchVO vo =new VisualColumnSearchVO();
								vo.setSearchType("2");
								vo.setVModel(fieldsModel.getVModel());
								vo.setValue(keyword);
								vo.setConfig(fieldsModel.getConfig());
								Boolean multiple = fieldsModel.getMultiple();
								vo.setMultiple(multiple);
								searchVOList.add(vo);
							}
						}
					}
					noSwapDataList = onlineSwapDataUtils.getSwapList(noSwapDataList, mainFieldModelList,visualDevJsonModel.getId(),false,new ArrayList<>());

					noSwapDataList= RelationFormUtils.getRelationListByKeyword(noSwapDataList, searchVOList);
				}else {
					noSwapDataList = onlineSwapDataUtils.getSwapList(noSwapDataList, mainFieldModelList,visualDevJsonModel.getId(),false,new ArrayList<>());
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//无表
		else{
			if (StringUtil.isNotEmpty(keyword)){
				for (FieLdsModel fieldsModel : fieLdsModels){
					if (fieldsModel.getVModel()!=null){
						boolean b = collect.stream().anyMatch(c ->
								fieldsModel.getVModel().equalsIgnoreCase(c)
						);
						//组装为查询条件
						if (b){
							VisualColumnSearchVO vo =new VisualColumnSearchVO();
							vo.setSearchType("2");
							vo.setVModel(fieldsModel.getVModel());
							vo.setValue(keyword);
							vo.setConfig(fieldsModel.getConfig());
							Boolean multiple = fieldsModel.getMultiple();
							vo.setMultiple(multiple);
							searchVOList.add(vo);
						}
					}
				}
			}
			noSwapDataList =this.getWithoutTableData(visualDevJsonModel.getId());

			noSwapDataList = onlineSwapDataUtils.getSwapList(noSwapDataList, mainFieldModelList,visualDevJsonModel.getId(),false,new ArrayList<>());
			if (searchVOList.size()>0){
				noSwapDataList = RelationFormUtils.getRelationListByKeyword(noSwapDataList, searchVOList);
			}
		}
		if (noSwapDataList.size()<1){
			return new ArrayList<>();
		}
		return noSwapDataList;
	}
}
